# -*- coding: utf-8 -*-
#
# Tubemaster
#
# Copyright (C) 2009 Selim Ok <selimok@gmail.com>
# Copyright (C) 2007-2008 Siegfried-Angel Gevatter Pujals <siggi.gevatter@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

# Tubemaster Visual Notifications
# This file contains all classes / functions related with visual notifications

try:
	import pynotify
	pynotify_is_available = True
except ImportError:
	pynotify_is_available = False

class Notification:
	"""This class handles the display of visual notification bubbles."""
	
	def __init__(self, settings, appname):
		"""Initialize the class."""
		
		self.notifications = []	# This list holds the instances of all notifications
		
		if pynotify_is_available is not True:
			return None
		
		self.settings = settings
		pynotify.init(appname)
		
	def showNotification(self, title, message, urgency=0, expires=15000, category='transfer', image='../data/tubemaster-32x32.png'):
		"""Displays a notification bubble."""
		
		if pynotify_is_available is not True:
			return 0
		
		if category == 'transfer.notifyDone' and not self.settings.value('Interface/notifyDone').toBool():
			return 0
		
		if category == 'transfer.notifyError' and not self.settings.value('Interface/notifyError').toBool():
			return 0
		
		image = '/'.join(__file__.split('/')[0:-1]) + '/' + image
		
		bubble = pynotify.Notification(title, message, image)
		
		bubble.set_category(category)
		bubble.set_hint('desktop-entry', 'tubemaster')
		# bubble.set_hint('x', '0')
		# bubble.set_hint('y', '0')
		
		if urgency == 0:
			bubble.set_urgency(pynotify.URGENCY_LOW)
		elif urgency == 2:
			bubble.set_urgency(pynotify.URGENCY_CRITICAL)
		
		if expires == 0:
			bubble.set_timeout(pynotify.EXPIRES_NEVER)
		else:
			bubble.set_timeout(expires)
		
		bubble.show()
		self.notifications.append(bubble)
		
	def getNotifications(self):
		"""Returns a list with the instances of all notifications."""
		
		return self.notifications
